!function ($) {
    $.extend({
        _jsonp: {
            scripts: {},
            counter: 1,
            charset: "gb2312",
            head: document.getElementsByTagName("head")[0],
            name: function (callback) {
                var name = "_jsonp_" + (new Date).getTime() + "_" + this.counter;
                this.counter++;
                var cb = function (json) {
                    eval("delete " + name),
                            callback(json),
                            $._jsonp.head.removeChild($._jsonp.scripts[name]),
                            delete $._jsonp.scripts[name]
                };
                return eval(name + " = cb"),
                        name
            },
            load: function (a, b) {
                var c = document.createElement("script");
                c.type = "text/javascript",
                        c.charset = this.charset,
                        c.src = a,
                        this.head.appendChild(c),
                        this.scripts[b] = c
            }
        },
        getJSONP: function (a, b) {
            var c = $._jsonp.name(b),
                    a = a.replace(/{callback};/, c);
            return $._jsonp.load(a, c),
                    this
        }
    })
}
(jQuery);

var iplocation = {"北京": {id: "1", c: 1},"天津": {id: "2", c: 2},"河北": {id: "3", c: 3},"山西": {id: "4", c: 4},"内蒙古": {id: "5", c: 5},"辽宁": {id: "6", c: 6},"吉林": {id: "7", c: 7},"黑龙江": {id: "8", c: 8},"上海": {id: "9", c: 9},"江苏": {id: "10", c: 10},"浙江": {id: "11", c: 11},"安徽": {id: "12", c: 12},"福建": {id: "13", c: 13},"江西": {id: "14", c: 14},"山东": {id: "15", c: 15},"河南": {id: "16", c: 16},"湖北": {id: "17", c: 17},"湖南": {id: "18", c: 18},"广东": {id: "19", c: 19},"广西": {id: "20", c: 20},"海南": {id: "21", c: 21},"重庆": {id: "22", c: 22},"四川": {id: "23", c: 23},"贵州": {id: "24", c: 24},"云南": {id: "25", c: 25},"西藏": {id: "26", c: 26},"陕西": {id: "27", c: 27},"甘肃": {id: "28", c: 28},"青海": {id: "29", c: 29},"宁夏": {id: "30", c: 30},"新疆": {id: "31", c: 31},"台湾": {id: "32", c: 32},"香港": {id: "33", c: 33},"澳门": {id: "34", c: 34},"海外": {id: "35", c: 35}};
var  provinceCityJson = {"1":[{"id": 36, "name": "北京市"}],"2":[{"id": 40, "name": "天津市"}],"3":[{"id": 73, "name": "石家庄市"},{"id": 74, "name": "唐山市"},{"id": 75, "name": "秦皇岛市"},{"id": 76, "name": "邯郸市"},{"id": 77, "name": "邢台市"},{"id": 78, "name": "保定市"},{"id": 79, "name": "张家口市"},{"id": 80, "name": "承德市"},{"id": 81, "name": "衡水市"},{"id": 82, "name": "廊坊市"},{"id": 83, "name": "沧州市"}],"4":[{"id": 84, "name": "太原市"},{"id": 85, "name": "大同市"},{"id": 86, "name": "阳泉市"},{"id": 87, "name": "长治市"},{"id": 88, "name": "晋城市"},{"id": 89, "name": "朔州市"},{"id": 90, "name": "晋中市"},{"id": 91, "name": "运城市"},{"id": 92, "name": "忻州市"},{"id": 93, "name": "临汾市"},{"id": 94, "name": "吕梁市"}],"5":[{"id": 95, "name": "呼和浩特市"},{"id": 96, "name": "包头市"},{"id": 97, "name": "乌海市"},{"id": 98, "name": "赤峰市"},{"id": 99, "name": "通辽市"},{"id": 100, "name": "鄂尔多斯市"},{"id": 101, "name": "呼伦贝尔市"},{"id": 102, "name": "巴彦淖尔市"},{"id": 103, "name": "乌兰察布市"},{"id": 104, "name": "兴安盟"},{"id": 105, "name": "锡林郭勒盟"},{"id": 106, "name": "阿拉善盟"}],"6":[{"id": 107, "name": "沈阳市"},{"id": 108, "name": "大连市"},{"id": 109, "name": "鞍山市"},{"id": 110, "name": "抚顺市"},{"id": 111, "name": "本溪市"},{"id": 112, "name": "丹东市"},{"id": 113, "name": "锦州市"},{"id": 114, "name": "营口市"},{"id": 115, "name": "阜新市"},{"id": 116, "name": "辽阳市"},{"id": 117, "name": "盘锦市"},{"id": 118, "name": "铁岭市"},{"id": 119, "name": "朝阳市"},{"id": 120, "name": "葫芦岛市"}],"7":[{"id": 121, "name": "长春市"},{"id": 122, "name": "吉林市"},{"id": 123, "name": "四平市"},{"id": 124, "name": "辽源市"},{"id": 125, "name": "通化市"},{"id": 126, "name": "白山市"},{"id": 127, "name": "松原市"},{"id": 128, "name": "白城市"},{"id": 129, "name": "延边朝鲜族自治州"}],"8":[{"id": 130, "name": "哈尔滨市"},{"id": 131, "name": "齐齐哈尔市"},{"id": 132, "name": "鸡西市"},{"id": 133, "name": "鹤岗市"},{"id": 134, "name": "双鸭山市"},{"id": 135, "name": "大庆市"},{"id": 136, "name": "伊春市"},{"id": 137, "name": "佳木斯市"},{"id": 138, "name": "七台河市"},{"id": 139, "name": "牡丹江市"},{"id": 140, "name": "黑河市"},{"id": 141, "name": "绥化市"},{"id": 142, "name": "大兴安岭地区"}],"9":[{"id": 39, "name": "上海市"}],"10":[{"id": 162, "name": "南京市"},{"id": 163, "name": "无锡市"},{"id": 164, "name": "徐州市"},{"id": 165, "name": "常州市"},{"id": 166, "name": "苏州市"},{"id": 167, "name": "南通市"},{"id": 168, "name": "连云港市"},{"id": 169, "name": "淮安市"},{"id": 170, "name": "盐城市"},{"id": 171, "name": "扬州市"},{"id": 172, "name": "镇江市"},{"id": 173, "name": "泰州市"},{"id": 174, "name": "宿迁市"}],"11":[{"id": 175, "name": "杭州市"},{"id": 176, "name": "宁波市"},{"id": 177, "name": "温州市"},{"id": 178, "name": "嘉兴市"},{"id": 179, "name": "湖州市"},{"id": 180, "name": "绍兴市"},{"id": 181, "name": "舟山市"},{"id": 182, "name": "衢州市"},{"id": 183, "name": "金华市"},{"id": 184, "name": "台州市"},{"id": 185, "name": "丽水市"}],"12":[{"id": 186, "name": "合肥市"},{"id": 187, "name": "芜湖市"},{"id": 188, "name": "蚌埠市"},{"id": 189, "name": "淮南市"},{"id": 190, "name": "马鞍山市"},{"id": 191, "name": "淮北市"},{"id": 192, "name": "铜陵市"},{"id": 193, "name": "安庆市"},{"id": 194, "name": "黄山市"},{"id": 195, "name": "滁州市"},{"id": 196, "name": "阜阳市"},{"id": 197, "name": "宿州市"},{"id": 198, "name": "巢湖市"},{"id": 199, "name": "六安市"},{"id": 200, "name": "亳州市"},{"id": 201, "name": "池州市"},{"id": 202, "name": "宣城市"}],"13":[{"id": 203, "name": "福州市"},{"id": 204, "name": "厦门市"},{"id": 205, "name": "莆田市"},{"id": 206, "name": "三明市"},{"id": 207, "name": "泉州市"},{"id": 208, "name": "漳州市"},{"id": 209, "name": "南平市"},{"id": 210, "name": "龙岩市"},{"id": 211, "name": "宁德市"}],"14":[{"id": 212, "name": "南昌市"},{"id": 213, "name": "景德镇市"},{"id": 214, "name": "萍乡市"},{"id": 215, "name": "九江市"},{"id": 216, "name": "新余市"},{"id": 217, "name": "鹰潭市"},{"id": 218, "name": "赣州市"},{"id": 219, "name": "吉安市"},{"id": 220, "name": "宜春市"},{"id": 221, "name": "抚州市"},{"id": 222, "name": "上饶市"}],"15":[{"id": 223, "name": "济南市"},{"id": 224, "name": "青岛市"},{"id": 225, "name": "淄博市"},{"id": 226, "name": "枣庄市"},{"id": 227, "name": "东营市"},{"id": 228, "name": "烟台市"},{"id": 229, "name": "潍坊市"},{"id": 230, "name": "济宁市"},{"id": 231, "name": "泰安市"},{"id": 232, "name": "威海市"},{"id": 233, "name": "日照市"},{"id": 234, "name": "莱芜市"},{"id": 235, "name": "临沂市"},{"id": 236, "name": "德州市"},{"id": 237, "name": "聊城市"},{"id": 238, "name": "滨州市"},{"id": 239, "name": "菏泽市"}],"16":[{"id": 240, "name": "郑州市"},{"id": 241, "name": "开封市"},{"id": 242, "name": "洛阳市"},{"id": 243, "name": "平顶山市"},{"id": 244, "name": "安阳市"},{"id": 245, "name": "鹤壁市"},{"id": 246, "name": "新乡市"},{"id": 247, "name": "焦作市"},{"id": 248, "name": "濮阳市"},{"id": 249, "name": "许昌市"},{"id": 250, "name": "漯河市"},{"id": 251, "name": "三门峡市"},{"id": 252, "name": "南阳市"},{"id": 253, "name": "商丘市"},{"id": 254, "name": "信阳市"},{"id": 255, "name": "周口市"},{"id": 256, "name": "驻马店市"},{"id": 257, "name": "济源市"}],"17":[{"id": 258, "name": "武汉市"},{"id": 259, "name": "黄石市"},{"id": 260, "name": "十堰市"},{"id": 261, "name": "宜昌市"},{"id": 262, "name": "襄樊市"},{"id": 263, "name": "鄂州市"},{"id": 264, "name": "荆门市"},{"id": 265, "name": "孝感市"},{"id": 266, "name": "荆州市"},{"id": 267, "name": "黄冈市"},{"id": 268, "name": "咸宁市"},{"id": 269, "name": "随州市"},{"id": 270, "name": "恩施土家族苗族自治州"},{"id": 271, "name": "仙桃市"},{"id": 272, "name": "潜江市"},{"id": 273, "name": "天门市"},{"id": 274, "name": "神农架林区"}],"18":[{"id": 275, "name": "长沙市"},{"id": 276, "name": "株洲市"},{"id": 277, "name": "湘潭市"},{"id": 278, "name": "衡阳市"},{"id": 279, "name": "邵阳市"},{"id": 280, "name": "岳阳市"},{"id": 281, "name": "常德市"},{"id": 282, "name": "张家界市"},{"id": 283, "name": "益阳市"},{"id": 284, "name": "郴州市"},{"id": 285, "name": "永州市"},{"id": 286, "name": "怀化市"},{"id": 287, "name": "娄底市"},{"id": 288, "name": "湘西土家族苗族自治州"}],"19":[{"id": 289, "name": "广州市"},{"id": 290, "name": "韶关市"},{"id": 291, "name": "深圳市"},{"id": 292, "name": "珠海市"},{"id": 293, "name": "汕头市"},{"id": 294, "name": "佛山市"},{"id": 295, "name": "江门市"},{"id": 296, "name": "湛江市"},{"id": 297, "name": "茂名市"},{"id": 298, "name": "肇庆市"},{"id": 299, "name": "惠州市"},{"id": 300, "name": "梅州市"},{"id": 301, "name": "汕尾市"},{"id": 302, "name": "河源市"},{"id": 303, "name": "阳江市"},{"id": 304, "name": "清远市"},{"id": 305, "name": "东莞市"},{"id": 306, "name": "中山市"},{"id": 307, "name": "潮州市"},{"id": 308, "name": "揭阳市"},{"id": 309, "name": "云浮市"}],"20":[{"id": 310, "name": "南宁市"},{"id": 311, "name": "柳州市"},{"id": 312, "name": "桂林市"},{"id": 313, "name": "梧州市"},{"id": 314, "name": "北海市"},{"id": 315, "name": "防城港市"},{"id": 316, "name": "钦州市"},{"id": 317, "name": "贵港市"},{"id": 318, "name": "玉林市"},{"id": 319, "name": "百色市"},{"id": 320, "name": "贺州市"},{"id": 321, "name": "河池市"},{"id": 322, "name": "来宾市"},{"id": 323, "name": "崇左市"}],"21":[{"id": 324, "name": "海口市"},{"id": 325, "name": "三亚市"},{"id": 326, "name": "五指山市"},{"id": 327, "name": "琼海市"},{"id": 328, "name": "儋州市"},{"id": 329, "name": "文昌市"},{"id": 330, "name": "万宁市"},{"id": 331, "name": "东方市"},{"id": 332, "name": "定安县"},{"id": 333, "name": "屯昌县"},{"id": 334, "name": "澄迈县"},{"id": 335, "name": "临高县"},{"id": 336, "name": "白沙黎族自治县"},{"id": 337, "name": "昌江黎族自治县"},{"id": 338, "name": "乐东黎族自治县"},{"id": 339, "name": "陵水黎族自治县"},{"id": 340, "name": "保亭黎族苗族自治县"},{"id": 341, "name": "琼中黎族苗族自治县"},{"id": 342, "name": "西沙群岛"},{"id": 343, "name": "南沙群岛"},{"id": 344, "name": "中沙群岛的岛礁及其海域"}],"22":[{"id": 62, "name": "重庆市"}],"23":[{"id": 385, "name": "成都市"},{"id": 386, "name": "自贡市"},{"id": 387, "name": "攀枝花市"},{"id": 388, "name": "泸州市"},{"id": 389, "name": "德阳市"},{"id": 390, "name": "绵阳市"},{"id": 391, "name": "广元市"},{"id": 392, "name": "遂宁市"},{"id": 393, "name": "内江市"},{"id": 394, "name": "乐山市"},{"id": 395, "name": "南充市"},{"id": 396, "name": "眉山市"},{"id": 397, "name": "宜宾市"},{"id": 398, "name": "广安市"},{"id": 399, "name": "达州市"},{"id": 400, "name": "雅安市"},{"id": 401, "name": "巴中市"},{"id": 402, "name": "资阳市"},{"id": 403, "name": "阿坝藏族羌族自治州"},{"id": 404, "name": "甘孜藏族自治州"},{"id": 405, "name": "凉山彝族自治州"}],"24":[{"id": 406, "name": "贵阳市"},{"id": 407, "name": "六盘水市"},{"id": 408, "name": "遵义市"},{"id": 409, "name": "安顺市"},{"id": 410, "name": "铜仁地区"},{"id": 411, "name": "黔西南布依族苗族自治州"},{"id": 412, "name": "毕节地区"},{"id": 413, "name": "黔东南苗族侗族自治州"},{"id": 414, "name": "黔南布依族苗族自治州"}],"25":[{"id": 415, "name": "昆明市"},{"id": 416, "name": "曲靖市"},{"id": 417, "name": "玉溪市"},{"id": 418, "name": "保山市"},{"id": 419, "name": "昭通市"},{"id": 420, "name": "丽江市"},{"id": 421, "name": "思茅市"},{"id": 422, "name": "临沧市"},{"id": 423, "name": "楚雄彝族自治州"},{"id": 424, "name": "红河哈尼族彝族自治州"},{"id": 425, "name": "文山壮族苗族自治州"},{"id": 426, "name": "西双版纳傣族自治州"},{"id": 427, "name": "大理白族自治州"},{"id": 428, "name": "德宏傣族景颇族自治州"},{"id": 429, "name": "怒江傈僳族自治州"},{"id": 430, "name": "迪庆藏族自治州"}],"26":[{"id": 431, "name": "拉萨市"},{"id": 432, "name": "昌都地区"},{"id": 433, "name": "山南地区"},{"id": 434, "name": "日喀则地区"},{"id": 435, "name": "那曲地区"},{"id": 436, "name": "阿里地区"},{"id": 437, "name": "林芝地区"}],"27":[{"id": 438, "name": "西安市"},{"id": 439, "name": "铜川市"},{"id": 440, "name": "宝鸡市"},{"id": 441, "name": "咸阳市"},{"id": 442, "name": "渭南市"},{"id": 443, "name": "延安市"},{"id": 444, "name": "汉中市"},{"id": 445, "name": "榆林市"},{"id": 446, "name": "安康市"},{"id": 447, "name": "商洛市"}],"28":[{"id": 448, "name": "兰州市"},{"id": 449, "name": "嘉峪关市"},{"id": 450, "name": "金昌市"},{"id": 451, "name": "白银市"},{"id": 452, "name": "天水市"},{"id": 453, "name": "武威市"},{"id": 454, "name": "张掖市"},{"id": 455, "name": "平凉市"},{"id": 456, "name": "酒泉市"},{"id": 457, "name": "庆阳市"},{"id": 458, "name": "定西市"},{"id": 459, "name": "陇南市"},{"id": 460, "name": "临夏回族自治州"},{"id": 461, "name": "甘南藏族自治州"}],"29":[{"id": 462, "name": "西宁市"},{"id": 463, "name": "海东地区"},{"id": 464, "name": "海北藏族自治州"},{"id": 465, "name": "黄南藏族自治州"},{"id": 466, "name": "海南藏族自治州"},{"id": 467, "name": "果洛藏族自治州"},{"id": 468, "name": "玉树藏族自治州"},{"id": 469, "name": "海西蒙古族藏族自治州"}],"30":[{"id": 470, "name": "银川市"},{"id": 471, "name": "石嘴山市"},{"id": 472, "name": "吴忠市"},{"id": 473, "name": "固原市"},{"id": 474, "name": "中卫市"}],"31":[{"id": 475, "name": "乌鲁木齐市"},{"id": 476, "name": "克拉玛依市"},{"id": 477, "name": "吐鲁番地区"},{"id": 478, "name": "哈密地区"},{"id": 479, "name": "昌吉回族自治州"},{"id": 480, "name": "博尔塔拉蒙古自治州"},{"id": 481, "name": "巴音郭楞蒙古自治州"},{"id": 482, "name": "阿克苏地区"},{"id": 483, "name": "克孜勒苏柯尔克孜自治州"},{"id": 484, "name": "喀什地区"},{"id": 485, "name": "和田地区"},{"id": 486, "name": "伊犁哈萨克自治州"},{"id": 487, "name": "塔城地区"},{"id": 488, "name": "阿勒泰地区"},{"id": 489, "name": "石河子市"},{"id": 490, "name": "阿拉尔市"},{"id": 491, "name": "图木舒克市"},{"id": 492, "name": "五家渠市"}],"32":[{"id": 493, "name": "台北市"},{"id": 494, "name": "高雄市"},{"id": 495, "name": "基隆市"},{"id": 496, "name": "台中市"},{"id": 497, "name": "台南市"},{"id": 498, "name": "新竹市"},{"id": 499, "name": "嘉义市"},{"id": 500, "name": "台北县"},{"id": 501, "name": "宜兰县"},{"id": 502, "name": "桃园县"},{"id": 503, "name": "新竹县"},{"id": 504, "name": "苗栗县"},{"id": 505, "name": "台中县"},{"id": 506, "name": "彰化县"},{"id": 507, "name": "南投县"},{"id": 508, "name": "云林县"},{"id": 509, "name": "嘉义县"},{"id": 510, "name": "台南县"},{"id": 511, "name": "高雄县"},{"id": 512, "name": "屏东县"},{"id": 513, "name": "澎湖县"},{"id": 514, "name": "台东县"},{"id": 515, "name": "花莲县"}],"33":[{"id": 516, "name": "中西区"},{"id": 517, "name": "东区"},{"id": 518, "name": "九龙城区"},{"id": 519, "name": "观塘区"},{"id": 520, "name": "南区"},{"id": 521, "name": "深水埗区"},{"id": 522, "name": "黄大仙区"},{"id": 523, "name": "湾仔区"},{"id": 524, "name": "油尖旺区"},{"id": 525, "name": "离岛区"},{"id": 526, "name": "葵青区"},{"id": 527, "name": "北区"},{"id": 528, "name": "西贡区"},{"id": 529, "name": "沙田区"},{"id": 530, "name": "屯门区"},{"id": 531, "name": "大埔区"},{"id": 532, "name": "荃湾区"},{"id": 533, "name": "元朗区"}],"34":[{"id": 534, "name": "澳门特别行政区"}],"35":[{"id": 45055, "name": "海外"}]}

var cName = "ipLocation";
var currentLocation = "北京";
var currentProvinceId = 1;

//根据省份ID获取名称
function getNameById(provinceId) {
    for (var o in iplocation) {
        if (iplocation[o] && iplocation[o].id == provinceId) {
            return o;
        }
    }
    return "北京";
}
var provinceHtml = '<div class="content"><div data-widget="tabs" class="m JD-stock" id="JD-stock">'
        + '<div class="mt">'
        + '    <ul class="tab">'
        + '        <li data-index="0" data-widget="tab-item" class="curr"><a href="#none" class="hover"><em>请选择</em><i></i></a></li>'
        + '        <li data-index="1" data-widget="tab-item" style="display:none;"><a href="#none" class=""><em>请选择</em><i></i></a></li>'
        + '        <li data-index="2" data-widget="tab-item" style="display:none;"><a href="#none" class=""><em>请选择</em><i></i></a></li>'
        + '        <li data-index="3" data-widget="tab-item" style="display:none;"><a href="#none" class=""><em>请选择</em><i></i></a></li>'
        + '    </ul>'
        + '    <div class="stock-line"></div>'
        + '</div>'
        + '<div class="mc" data-area="0" data-widget="tab-content" id="stock_province_item">'
        + '    <ul class="area-list">'
        + '       <li><a href="#none" data-value="1">北京</a></li><li><a href="#none" data-value="2">天津</a></li><li><a href="#none" data-value="3">河北</a></li><li><a href="#none" data-value="4">山西</a></li><li><a href="#none" data-value="5">内蒙古</a></li><li><a href="#none" data-value="6">辽宁</a></li><li><a href="#none" data-value="7">吉林</a></li><li><a href="#none" data-value="8">黑龙江</a></li><li><a href="#none" data-value="9">上海</a></li><li><a href="#none" data-value="10">江苏</a></li><li><a href="#none" data-value="11">浙江</a></li><li><a href="#none" data-value="12">安徽</a></li><li><a href="#none" data-value="13">福建</a></li><li><a href="#none" data-value="14">江西</a></li><li><a href="#none" data-value="15">山东</a></li><li><a href="#none" data-value="16">河南</a></li><li><a href="#none" data-value="17">湖北</a></li><li><a href="#none" data-value="18">湖南</a></li><li><a href="#none" data-value="19">广东</a></li><li><a href="#none" data-value="20">广西</a></li><li><a href="#none" data-value="21">海南</a></li><li><a href="#none" data-value="22">重庆</a></li><li><a href="#none" data-value="23">四川</a></li><li><a href="#none" data-value="24">贵州</a></li><li><a href="#none" data-value="25">云南</a></li><li><a href="#none" data-value="26">西藏</a></li><li><a href="#none" data-value="27">陕西</a></li><li><a href="#none" data-value="28">甘肃</a></li><li><a href="#none" data-value="29">青海</a></li><li><a href="#none" data-value="30">宁夏</a></li><li><a href="#none" data-value="31">新疆</a></li><li><a href="#none" data-value="32">台湾</a></li><li><a href="#none" data-value="33">香港</a></li><li><a href="#none" data-value="34">澳门</a></li><li><a href="#none" data-value="35">海外</a></li>'
        + '    </ul>'
        + '</div>'
        + '<div class="mc" data-area="1" data-widget="tab-content" id="stock_city_item"></div>'
        + '<div class="mc" data-area="2" data-widget="tab-content" id="stock_area_item"></div>'
        + '<div class="mc" data-area="3" data-widget="tab-content" id="stock_town_item"></div>'
        + '</div></div>';
function getAreaList(result) {
    var html = ["<ul class='area-list'>"];
    var longhtml = [];
    var longerhtml = [];
    if (result && result.length > 0) {
        for (var i = 0, j = result.length; i < j; i++) {
            result[i].name = result[i].name.replace(" ", "");
            if (result[i].name.length > 12) {
                longerhtml.push("<li class='longer-area'><a href='#none' data-value='" + result[i].id + "'>" + result[i].name + "</a></li>");
            } else if (result[i].name.length > 5) {
                longhtml.push("<li class='long-area'><a href='#none' data-value='" + result[i].id + "'>" + result[i].name + "</a></li>");
            } else {
                html.push("<li><a href='#none' data-value='" + result[i].id + "'>" + result[i].name + "</a></li>");
            }
        }
    } else {
        html.push("<li><a href='#none' data-value='" + currentAreaInfo.currentFid + "'> </a></li>");
    }
    html.push(longhtml.join(""));
    html.push(longerhtml.join(""));
    html.push("</ul>");
    return html.join("");
}
function cleanKuohao(str) {
    if (str && str.indexOf("(") > 0) {
        str = str.substring(0, str.indexOf("("));
    }
    if (str && str.indexOf("（") > 0) {
        str = str.substring(0, str.indexOf("（"));
    }
    return str;
}

function getStockOpt(id, name) {
    if (currentAreaInfo.currentLevel == 3) {
        currentAreaInfo.currentAreaId = id;
        currentAreaInfo.currentAreaName = name;
        if (!page_load) {
            currentAreaInfo.currentTownId = 0;
            currentAreaInfo.currentTownName = "";
        }
    } else if (currentAreaInfo.currentLevel == 4) {
        currentAreaInfo.currentTownId = id;
        currentAreaInfo.currentTownName = name;
    }
    //添加20140224
    $('#store-selector').removeClass('hover');
    //setCommonCookies(currentAreaInfo.currentProvinceId,currentLocation,currentAreaInfo.currentCityId,currentAreaInfo.currentAreaId,currentAreaInfo.currentTownId,!page_load);
    if (page_load) {
        page_load = false;
    }
    //替换gSC
    var address = currentAreaInfo.currentProvinceName + currentAreaInfo.currentCityName + currentAreaInfo.currentAreaName + currentAreaInfo.currentTownName;
    $("#store-selector .text div").html(currentAreaInfo.currentProvinceName + cleanKuohao(currentAreaInfo.currentCityName) + cleanKuohao(currentAreaInfo.currentAreaName) + cleanKuohao(currentAreaInfo.currentTownName)).attr("title", address);
}
function getAreaListcallback(r) {
    currentDom.html(getAreaList(r));
    if (currentAreaInfo.currentLevel >= 2) {
        currentDom.find("a").click(function () {
            if (page_load) {
                page_load = false;
            }
            if (currentDom.attr("id") == "stock_area_item") {
                currentAreaInfo.currentLevel = 3;
            } else if (currentDom.attr("id") == "stock_town_item") {
                currentAreaInfo.currentLevel = 4;
            }
            getStockOpt($(this).attr("data-value"), $(this).html());
        });
        if (page_load) { //初始化加载
            currentAreaInfo.currentLevel = currentAreaInfo.currentLevel == 2 ? 3 : 4;
            if (currentAreaInfo.currentAreaId && new Number(currentAreaInfo.currentAreaId) > 0) {
                getStockOpt(currentAreaInfo.currentAreaId, currentDom.find("a[data-value='" + currentAreaInfo.currentAreaId + "']").html());
            } else {
                getStockOpt(currentDom.find("a").eq(0).attr("data-value"), currentDom.find("a").eq(0).html());
            }
        }
    }
}
function chooseProvince(provinceId) {
    provinceContainer.hide();
    currentAreaInfo.currentLevel = 1;
    currentAreaInfo.currentProvinceId = provinceId;
    currentAreaInfo.currentProvinceName = getNameById(provinceId);
    if (!page_load) {
        currentAreaInfo.currentCityId = 0;
        currentAreaInfo.currentCityName = "";
        currentAreaInfo.currentAreaId = 0;
        currentAreaInfo.currentAreaName = "";
        currentAreaInfo.currentTownId = 0;
        currentAreaInfo.currentTownName = "";
    }
    areaTabContainer.eq(0).removeClass("curr").find("em").html(currentAreaInfo.currentProvinceName);
    areaTabContainer.eq(1).addClass("curr").show().find("em").html("请选择");
    areaTabContainer.eq(2).hide();
    areaTabContainer.eq(3).hide();
    cityContainer.show();
    areaContainer.hide();
    townaContainer.hide();
    if (provinceCityJson["" + provinceId]) {
        cityContainer.html(getAreaList(provinceCityJson["" + provinceId]));
        cityContainer.find("a").click(function () {
            if (page_load) {
                page_load = false;
            }
            $("#store-selector").unbind("mouseout");
            chooseCity($(this).attr("data-value"), $(this).html());
        });
        if (page_load) { //初始化加载
            if (currentAreaInfo.currentCityId && new Number(currentAreaInfo.currentCityId) > 0) {
                chooseCity(currentAreaInfo.currentCityId, cityContainer.find("a[data-value='" + currentAreaInfo.currentCityId + "']").html());
            } else {
                chooseCity(cityContainer.find("a").eq(0).attr("data-value"), cityContainer.find("a").eq(0).html());
            }
        }
    }
}
function chooseCity(cityId, cityName) {
    provinceContainer.hide();
    cityContainer.hide();
    currentAreaInfo.currentLevel = 2;
    currentAreaInfo.currentCityId = cityId;
    currentAreaInfo.currentCityName = cityName;
    if (!page_load) {
        currentAreaInfo.currentAreaId = 0;
        currentAreaInfo.currentAreaName = "";
        currentAreaInfo.currentTownId = 0;
        currentAreaInfo.currentTownName = "";
    }
    areaTabContainer.eq(1).removeClass("curr").find("em").html(cityName);
    areaTabContainer.eq(2).addClass("curr").show().find("em").html("请选择");
    areaTabContainer.eq(3).hide();
    areaContainer.show().html("<div class='iloading'>正在加载中，请稍候...</div>");
    townaContainer.hide();
    currentDom = areaContainer;
    $.getJSON(homeUrl+"/Public/AreaJson?id=" + cityId+"&transport_id="+$("#goods_transport").val(), function (result) {
        getAreaListcallback(result.data);
        $("#good_freight").html(result.freight);
    });
}
function chooseArea(areaId, areaName) {
    provinceContainer.hide();
    cityContainer.hide();
    areaContainer.hide();
    currentAreaInfo.currentLevel = 3;
    currentAreaInfo.currentAreaId = areaId;
    currentAreaInfo.currentAreaName = areaName;
    if (!page_load) {
        currentAreaInfo.currentTownId = 0;
        currentAreaInfo.currentTownName = "";
    }
    areaTabContainer.eq(2).removeClass("curr").find("em").html(areaName);
    areaTabContainer.eq(3).addClass("curr").show().find("em").html("请选择");
    townaContainer.show().html("<div class='iloading'>正在加载中，请稍候...</div>");
    currentDom = townaContainer;
    $.getJSON(homeUrl+"/Public/AreaJson?id=" + cityId+"&transport_id="+$("#goods_transport").val(), function (result) {
        getAreaListcallback(result.data);
        $("#good_freight").html(result.freight);
    });
}
$("#store-selector .text").after(provinceHtml);
var areaTabContainer = $("#JD-stock .tab li");
var provinceContainer = $("#stock_province_item");
var cityContainer = $("#stock_city_item");
var areaContainer = $("#stock_area_item");
var townaContainer = $("#stock_town_item");
var currentDom = provinceContainer;
//当前地域信息
var currentAreaInfo;
//初始化当前地域信息
function CurrentAreaInfoInit() {
    currentAreaInfo = {"currentLevel": 1, "currentProvinceId": 2, "currentProvinceName": "上海", "currentCityId": 0, "currentCityName": "", "currentAreaId": 0, "currentAreaName": "", "currentTownId": 2, "currentTownName": ""};
    var ipLoc = getCookie("ipLoc-djd");
    ipLoc = ipLoc ? ipLoc.split("-") : [16, 240, 2664, 0];
    if (ipLoc.length > 0 && ipLoc[0]) {
        currentAreaInfo.currentProvinceId = ipLoc[0];
        currentAreaInfo.currentProvinceName = getNameById(ipLoc[0]);
    }
    if (ipLoc.length > 1 && ipLoc[1]) {
        currentAreaInfo.currentCityId = ipLoc[1];
    }
    if (ipLoc.length > 2 && ipLoc[2]) {
        currentAreaInfo.currentAreaId = ipLoc[2];
    }
    if (ipLoc.length > 3 && ipLoc[3]) {
        currentAreaInfo.currentTownId = ipLoc[3];
    }
}
var page_load = true;
(function () {
    $("#store-selector").unbind("mousedown").bind("mousedown", function () {
        $('#store-selector').addClass('hover');
        $("#store-selector .content,#JD-stock").show();
    }).find("dl").remove();
    CurrentAreaInfoInit();
    areaTabContainer.eq(0).find("a").click(function () {
        areaTabContainer.removeClass("curr");
        areaTabContainer.eq(0).addClass("curr").show();
        provinceContainer.show();
        cityContainer.hide();
        areaContainer.hide();
        townaContainer.hide();
        areaTabContainer.eq(1).hide();
        areaTabContainer.eq(2).hide();
        areaTabContainer.eq(3).hide();
    });
    areaTabContainer.eq(1).find("a").click(function () {
        areaTabContainer.removeClass("curr");
        areaTabContainer.eq(1).addClass("curr").show();
        provinceContainer.hide();
        cityContainer.show();
        areaContainer.hide();
        townaContainer.hide();
        areaTabContainer.eq(2).hide();
        areaTabContainer.eq(3).hide();
    });
    areaTabContainer.eq(2).find("a").click(function () {
        areaTabContainer.removeClass("curr");
        areaTabContainer.eq(2).addClass("curr").show();
        provinceContainer.hide();
        cityContainer.hide();
        areaContainer.show();
        townaContainer.hide();
        areaTabContainer.eq(3).hide();
    });
    provinceContainer.find("a").click(function () {
        if (page_load) {
            page_load = false;
        }
        $("#store-selector").unbind("mouseout");
        chooseProvince($(this).attr("data-value"));
    }).end();
    chooseProvince(currentAreaInfo.currentProvinceId);
})();

function getCookie(name) {
    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1)
        return null;
    var end = document.cookie.indexOf(';', len);
    if (end == -1)
        end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}
;





